package logic

import (
	"context"
	"week1/ordersrv/service"

	"week1/ordersrv/internal/svc"
	"week1/ordersrv/ordersrv"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetOrderDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetOrderDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderDetailLogic {
	return &GetOrderDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetOrderDetailLogic) GetOrderDetail(in *ordersrv.GetOrderDetailReq) (*ordersrv.GetOrderDetailRes, error) {
	// todo: add your logic here and delete this line
	order, err := service.GetOrderByOrderSn(in.OrderSn)
	if err != nil {
		return nil, err
	}
	return &ordersrv.GetOrderDetailRes{OrderTotal: float32(order.OrderTotal)}, nil
}
